<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>招领网后台管理系统入口</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link rel="stylesheet" th:href="@{/static/css/bootstrap.css}">
    <link rel="stylesheet" th:href="@{/static/css/style.css}">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
    <script th:src="@{/static/layui/layui.js}"></script>
    <script th:src="@{/static/js/md5.js}"></script>
</head>
<body>
<div align="center" class="container">
    <div class="col-md-6" style="margin-top: 20%;">
        <div class="inset">
            <form id="login" name="login">
                <input name="enews" type="hidden" value="login">
                <div>
                    <h2>招领网后台管理系统</h2>
                    <span style="text-align: left;text-indent: 0.4em;"><label>用户名</label></span>
                    <span><input class="username" name="username" type="text" value="admin"></span>
                </div>
                <div>
                    <span style="text-align: left;text-indent: 0.4em;"><label>密码</label></span>
                    <span><input class="password" name="password" type="password" value="1234"></span>
                </div>
                <div class="sign">
                    <input class="su" type="reset" value="重置"/>
                    <input class="su submit" type="button" value="登录"/>
                </div>
            </form>
        </div>
    </div>
</div>

<script th:inline="javascript">
    //获取application里配置的路径 如：context-path: /yz

    var ctx = [[@{/}]];
        layui.use('jquery', function () {
            var $ = layui.jquery;


            $('.submit').click(function () {
                let user_name = $('.username').val();
                let pass_word = $('.password').val();

                console.log({
                    user_name: user_name,
                    pass_word: pass_word
                })
                const yan = '!a@n%p&';
                pass_word = md5(yan + pass_word + yan);
                if (user_name !== '') {
                    if (pass_word !== '') {
                        $.ajax({
                            type: "POST",
                            url: "/toLogin",
                            data: JSON.stringify({userName: user_name, passWord: pass_word}),
                            dataType: "json",
                            contentType: "application/json;charset=UTF-8",
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg('登录成功', {icon: 6, time: 1300}, function () {
                                        window.location = ctx + "index";
                                    })
                                } else if (res.code === 114) {

                                    //强行登录
                                    layer.open({
                                        title: '系统提示',
                                        content: res.msg + "<p style='color: red;text-align: center'>是否强行登录</p> ",
                                        icon: 6,
                                        btn: ['确定', '取消'],
                                        yes: function (index, layero) {
                                            console.log("11111111111111111111111111");
                                            $.ajax({
                                                type: "POST",
                                                url: "/toLoginTo",
                                                data: JSON.stringify({userName: user_name, passWord: pass_word}),
                                                dataType: "json",
                                                contentType: "application/json;charset=UTF-8",
                                                success: function (res) {
                                                    if (res.code === 200) {
                                                        layer.msg('登录成功', {icon: 6, time: 1300}, function () {
                                                            window.location = ctx + "index";
                                                        })
                                                    }
                                                }
                                            })
                                        },
                                        cancel: function () {
                                            //右上角关闭回调
                                            // window.location.href='extendedinfo.html';
                                            return false //开启该代码可禁止点击该按钮关闭
                                        }
                                    });
                                } else {
                                    layer.msg(res.msg);
                                }
                                console.log(res)
                            }
                        })
                    } else {
                        layer.msg("密码不能为空");
                    }
                } else {
                    layer.msg("用户名不能为空");
                }
            })
        })


</script>

</body>
</html>